package com.me.study.dao;

import javax.annotation.PreDestroy;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;

/**
 * 
 *
 * @author ME
 * @date   2019/9/26
 */
@Repository
@Scope("singleton")
public class IndexDaoImpl1 implements IndexDao, InitializingBean, ApplicationContextAware {

	private ApplicationContext applicationContext;

	public IndexDaoImpl1() {
		System.out.println("Construct [IndexDaoImpl1]：TestBeanFactoryPostProcessor 中会把 Scope 改为原型");
	}

	@PostConstruct
	public void init() {
		System.out.println("【Spring】 PostConstruct: dao1");
	}

	@PreDestroy
	public void destroy() {
		System.out.println("【Spring】 PreDestroy: dao1");
	}

	@Override
    public void query() {
        System.out.println("dao1.query()");
    }

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("【Spring】 afterPropertiesSet(): dao1");
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext = applicationContext;
	}

	public ApplicationContext getApplicationContext() {
		return this.applicationContext;
	}
}
